package com.ocom.webapi.controller;


import com.ocom.common.constant.CompanyServiceUrl;
import com.ocom.common.request.company.GetLoginCompanyListRequest;
import com.ocom.common.resp.Result;
import com.ocom.webapi.feign.CompanyClientService;
import com.ocom.webapi.service.UnitAccountService;
import com.ocom.webapi.vo.unitaccount.*;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

//@Slf4j
@RestController
@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
public class UnitAccountController {
    private final Logger log = LoggerFactory.getLogger(VisitorApproverController.class);

    @Autowired
    private UnitAccountService unitAccountService;

    @Autowired
    private CompanyClientService companyClientService;

    /**
     * 单位账号列表（UnitAccount/onShow）
     * */
    @PostMapping(CompanyServiceUrl.URL_UnitAccountOnShow)
    public Result UnitAccountOnShow(@Validated @RequestBody OnShowVo onShowVo){
        log.info("单位账号列表请求参数:{{}}",onShowVo);
        return unitAccountService.UnitAccountOnShow(onShowVo);
    }


    @PostMapping(CompanyServiceUrl.URL_UnitAccountOnShowB)
    public Result UnitAccountOnShowB(@RequestBody GetLoginCompanyListRequest request){
        request.setQueryMode(1);
        return this.companyClientService.getLoginCompanyList(request);
    }

    /**
     * 新增单位账号（UnitAccount/add）
     * */
    @PostMapping(CompanyServiceUrl.URL_UnitAccountAdd)
    public Result UnitAccountAdd(@Validated @RequestBody AddVo addVo){
        log.info("新增单位账号请求参数:{{}}",addVo);
        return unitAccountService.UnitAccountAdd(addVo);
    }

    /**
     * 修改单位账号（UnitAccount/modify）
     * */
    @PostMapping(CompanyServiceUrl.URL_UnitAccountModify)
    public Result UnitAccountModify(@Validated @RequestBody ModifyVo modifyVo){
        log.info("修改单位账号请求参数:{{}}",modifyVo);
        return unitAccountService.UnitAccountModify(modifyVo);
    }

    /**
     * 启用/禁用单位账号（UnitAccount/modifyStatus）
     * */
    @PostMapping(CompanyServiceUrl.URL_UnitAccountModifyStatus)
    public Result UnitAccountModifyStatus(@Validated @RequestBody ModifyStatusVo modifyStatusVo){
        log.info("修改单位账号请求参数:{{}}",modifyStatusVo);
        return unitAccountService.UnitAccountModifyStatus(modifyStatusVo);
    }


    /**
     * 修改单位账号密码（UnitAccout/modifyPwd）
     * */
    @PostMapping(CompanyServiceUrl.URL_UnitAccountModifyPwd)
    public Result UnitAccountModifyPwd(@Validated @RequestBody ModifyPwdVo modifyStatusVo){
        log.info("修改单位账号请求参数:{{}}",modifyStatusVo);
        return unitAccountService.UnitAccountModifyPwd(modifyStatusVo);
    }
}
